<template>
  <div class="box">
    <!-- 寄语 -->
    <div class="originalIntention">
      <img :src="originalIntention" alt="" />
    </div>
    <!-- 用户信息 -->
    <div class="info">
      <div class="user">
        <el-form
          ref="userForm"
          :model="userForm"
          :rules="rules"
          label-width="90px"
          :hide-required-asterisk="true"
        >
          <!-- 第一行 - 出生日期 -->
          <div class="bgc">
            <el-form-item label="出生日期:" prop="birthDate">
              <el-col :span="11">
                <el-date-picker
                  type="date"
                  placeholder="选择您的出生日期"
                  v-model="userForm.birthDate"
                ></el-date-picker>
              </el-col>
            </el-form-item>
          </div>
          <!-- 第二行 - 性别 -->
          <div class="bgc">
            <el-form-item label="您的性别:" prop="gender">
              <el-select v-model="userForm.gender" placeholder="请选择您的性别">
                <el-option label="男" value="男"></el-option>
                <el-option label="女" value="女"></el-option>
              </el-select>
            </el-form-item>
          </div>
          <!-- 第三行 - 身高 -->
          <div class="bgc">
            <el-form-item label="您的身高:" prop="bodyHeight">
              <el-input
                v-model.number.trim="userForm.bodyHeight"
                placeholder="请输入您的身高(cm)"
              ></el-input>
            </el-form-item>
          </div>
          <!-- 第五行 - 心态 -->
          <div class="bgc">
            <el-form-item label="您的心态:" prop="mentality">
              <el-select v-model="userForm.mentality" placeholder="请选择您的心态">
                <el-option label="乐观" value="乐观"></el-option>
                <el-option label="多数时间感到快乐满足" value="多数时间感到快乐满足"></el-option>
                <el-option label="自卑" value="自卑"></el-option>
                <el-option label="信仰坚定" value="信仰坚定"></el-option>
                <el-option label="爱冒险" value="爱冒险"></el-option>
                <el-option label="抑郁" value="抑郁"></el-option>
              </el-select>
            </el-form-item>
          </div>
          <!-- 第六行 - 吸烟情况 -->
          <div class="bgc">
            <el-form-item label="吸烟情况:" prop="smoke">
              <el-select v-model="userForm.smoke" placeholder="请选择您的吸烟情况">
                <el-option label="从不吸烟" value="从不吸烟"></el-option>
                <el-option label="偶尔吸烟" value="偶尔吸烟"></el-option>
                <el-option label="经常吸烟" value="经常吸烟"></el-option>
              </el-select>
            </el-form-item>
          </div>
          <!-- 按钮 -->
          <el-button type="warning" @click="sub">提交</el-button>
        </el-form>
      </div>
    </div>
    <!-- 声明 -->
    <div class="statement">
      <img :src="statement" alt="" />
    </div>
  </div>
</template>

<script>
import originalIntention from '@/assets/初衷.png'
import statement from '@/assets/声明.png'
export default {
  name: 'UserInfo',
  data () {
    return {
      // 初衷
      originalIntention: originalIntention,
      // 声明
      statement: statement,
      // 用户填写的信息表格
      userForm: {
        // 出生日期
        birthDate: '',
        // 性别
        gender: '',
        // 身高
        bodyHeight: '',
        // 心态
        mentality: '乐观',
        // 吸烟情况
        smoke: '从不吸烟'
      },
      // 校验规则
      rules: {
        birthDate: [{ required: true, message: '请输入出生日期', trigger: ['blur', 'change'] }],
        gender: [{ required: true, message: '请输入性别', trigger: ['blur', 'change'] }],
        bodyHeight: [{ required: true, message: '请输入身高', trigger: ['blur', 'change'] }],
        mentality: [{ required: true, message: '请输入心态', trigger: ['blur', 'change'] }],
        smoke: [{ required: true, message: '请输入吸烟情况', trigger: ['blur', 'change'] }]
      },
      // 结果
      lifeRes: {
        lifePercentage: '', // 百分比
        lifeSecond: '', // 秒
        lifeDay: '', // 天
        lifeMonth: '', // 月
        lifeYear: '', // 年
        lifeEat: '', // 吃
        lifeToilet: '', // 厕所
        lifeMovie: '', // 电影
        lifeLongHolidays: '', // 长假
        wash: '' // 洗澡
      }
    }
  },
  methods: {
    sub () {
      this.$refs.userForm.validate(valid => {
        if (!valid) return
        // 提示
        this.$message({
          message: '提交成功',
          type: 'success',
          customClass: 'messageIndex'
        })

        // 当前日期
        const date = new Date()
        // 出生日期
        const nowTime = this.userForm.birthDate
        // 死亡日期
        const deathDate = new Date(
          `${nowTime.getFullYear() + 80}/${nowTime.getMonth() + 1}/${nowTime.getDate()}`
        )
        // 计算结果
        const restSec = new Date(deathDate - date)
        // 剩余天数
        this.lifeRes.lifeDay = parseInt(restSec / (60 * 60 * 24 * 1000))
        // 年
        this.lifeRes.lifeYear = (this.lifeRes.lifeDay / 365).toFixed(0)
        // 月
        this.lifeRes.lifeMonth = this.lifeRes.lifeYear * 12
        // 百分比
        this.lifeRes.lifePercentage = (this.lifeRes.lifeYear / 80).toFixed(2) * 100
        // 小时
        const hour = this.lifeRes.lifeDay * 24
        // 分
        const minute = hour * 60
        // 秒
        this.lifeRes.lifeSecond = minute * 60
        // 吃
        this.lifeRes.lifeEat = this.lifeRes.lifeDay * 3
        // 拉
        this.lifeRes.lifeToilet = this.lifeRes.lifeDay * 5
        // 看
        this.lifeRes.lifeMovie = this.lifeRes.lifeYear * 6
        // 假
        this.lifeRes.lifeLongHolidays = this.lifeRes.lifeYear * 3
        // 洗
        this.lifeRes.wash = (this.lifeRes.lifeDay / 2).toFixed(0)
        localStorage.setItem('user', JSON.stringify(this.lifeRes))
        // 清空信息
        this.$refs.userForm.resetFields()
        this.$router.push('/Home')
      })
    }
  }
}
</script>

<style lang="less" >
.messageIndex {
  min-width: 130px !important;
}
</style>
<style lang="less" scoped>
.box {
  background: url('../../assets/loginBgc.jpg') 0px;
  background-size: cover;
  height: 100%;
  position: relative;
  overflow: hidden;

  // 寄语
  .originalIntention {
    img {
      margin-top: 10px;
      position: absolute;
      left: -145px;
      top: -10px;
      transform: scale(0.5);
    }
  }
  // 用户信息
  .info {
    color: #fff;
    width: 90%;
    position: absolute;
    left: 10px;
    top: 130px;
    border: 10px solid #000;
    border-image-slice: 20 20 20 20;
    border-image-source: url('../../assets/边框.png');
    background-color: rgba(0, 0, 0, 0.7);
    .user {
      box-sizing: border-box;
      width: 100%;
      height: 100%;
      padding: 15px;
      .bgc {
        border-radius: 5px;
        /deep/ .el-form-item__label {
          font-size: 18px;
          color: #fbecac;
        }
        /deep/ .el-input {
          font-size: 16px;
          color: #fbecac;
        }
        /deep/ .el-input__inner {
          background-color: transparent;
          color: #fbecac;
        }
        /deep/ .el-input__inner::placeholder {
          background: linear-gradient(to right, #fbecac, #e0bc61);
          background-clip: text;
          color: transparent;
        }
      }
      .el-button--warning {
        width: 200px;
        margin-left: 50%;
        transform: translateX(-50%);
        background: linear-gradient(to top left, #fbecac, transparent, #e0bc61);
        font-size: 18px;
        color: #fff;
        font-weight: 900;
      }
    }
  }
  // 声明
  /deep/ .statement {
    position: absolute;
    padding: 10px;
    bottom: 0;
    transform: scale(0.5);
    background-color: rgba(0, 0, 0, 0.7);
    border-radius: 35px;
    display: flex;
  }
}
</style>
